package com.konne.nightmare.FastPublicOpinion.mvp.presenter;


import com.google.gson.Gson;
import com.konne.nightmare.FastPublicOpinion.base.BaseMvpPresenter;
import com.konne.nightmare.FastPublicOpinion.base.OnLoadDataListener;
import com.konne.nightmare.FastPublicOpinion.bean.OpinionDataBean;
import com.konne.nightmare.FastPublicOpinion.bean.OpinionDetailDataBean;
import com.konne.nightmare.FastPublicOpinion.http.BaseResponse;
import com.konne.nightmare.FastPublicOpinion.mvp.model.IHomeDetailModel;
import com.konne.nightmare.FastPublicOpinion.mvp.model.impl.HomeDetilModelImpl;
import com.konne.nightmare.FastPublicOpinion.mvp.view.IHomeDetailView;


public class HomeDetailPresenter extends BaseMvpPresenter<IHomeDetailView> {

    private IHomeDetailModel iHomeDetailModel;

    public HomeDetailPresenter() {
        iHomeDetailModel = new HomeDetilModelImpl();
    }

    public void getOpinionDetail(int id){
        if (mView == null) return;

        iHomeDetailModel.responseOpinionDetail(id, new OnLoadDataListener<OpinionDetailDataBean.ResponseDataBean>() {
            @Override
            public void onSuccess(BaseResponse<OpinionDetailDataBean.ResponseDataBean> t) {
                mView.getOpinionDetail(t);
            }

            @Override
            public void onFailure(String error) {
                mView.responseFailed(error);
            }
        });
    }

    public void postOpinionAddCollect(int id){
        if (mView == null) return;

        OpinionDataBean.RequestIdDataBean bean = new OpinionDataBean.RequestIdDataBean();
        bean.setIds(id);

        iHomeDetailModel.postOpinionAddCollect(new Gson().toJson(bean), new OnLoadDataListener<String>() {
            @Override
            public void onSuccess(BaseResponse<String> t) {
                mView.postOpinionCWBD(t);
            }

            @Override
            public void onFailure(String error) {
                mView.responseFailed(error);
            }
        });
    }

    public void postOpinionCancelCollect(int id){
        if (mView == null) return;

        OpinionDataBean.RequestIdDataBean bean = new OpinionDataBean.RequestIdDataBean();
        bean.setIds(id);

        iHomeDetailModel.postOpinionCancelCollect(new Gson().toJson(bean), new OnLoadDataListener<String>() {
            @Override
            public void onSuccess(BaseResponse<String> t) {
                mView.postOpinionCWBD(t);
            }

            @Override
            public void onFailure(String error) {
                mView.responseFailed(error);
            }
        });
    }

    public void postOpinionAddWarning(int id){
        if (mView == null) return;

        OpinionDataBean.RequestIdDataBean bean = new OpinionDataBean.RequestIdDataBean();
        bean.setIds(id);

        iHomeDetailModel.postOpinionAddWarning(new Gson().toJson(bean), new OnLoadDataListener<String>() {
            @Override
            public void onSuccess(BaseResponse<String> t) {
                mView.postOpinionCWBD(t);
            }

            @Override
            public void onFailure(String error) {
                mView.responseFailed(error);
            }
        });
    }

    public void postOpinionCancelWarning(int id){
        if (mView == null) return;

        OpinionDataBean.RequestIdDataBean bean = new OpinionDataBean.RequestIdDataBean();
        bean.setIds(id);

        iHomeDetailModel.postOpinionCancelWarning(new Gson().toJson(bean), new OnLoadDataListener<String>() {
            @Override
            public void onSuccess(BaseResponse<String> t) {
                mView.postOpinionCWBD(t);
            }

            @Override
            public void onFailure(String error) {
                mView.responseFailed(error);
            }
        });
    }

    public void postOpinionAddBriefing(int id){
        if (mView == null) return;

        OpinionDataBean.RequestIdDataBean bean = new OpinionDataBean.RequestIdDataBean();
        bean.setIds(id);

        iHomeDetailModel.postOpinionAddBriefing(new Gson().toJson(bean), new OnLoadDataListener<String>() {
            @Override
            public void onSuccess(BaseResponse<String> t) {
                mView.postOpinionCWBD(t);
            }

            @Override
            public void onFailure(String error) {
                mView.responseFailed(error);
            }
        });
    }

    public void postOpinionCancelBriefing(int id){
        if (mView == null) return;

        OpinionDataBean.RequestIdDataBean bean = new OpinionDataBean.RequestIdDataBean();
        bean.setIds(id);

        iHomeDetailModel.postOpinionCancelBriefing(new Gson().toJson(bean), new OnLoadDataListener<String>() {
            @Override
            public void onSuccess(BaseResponse<String> t) {
                mView.postOpinionCWBD(t);
            }

            @Override
            public void onFailure(String error) {
                mView.responseFailed(error);
            }
        });
    }

    public void postOpinionDelete(int id){
        if (mView == null) return;

        OpinionDataBean.RequestIdDataBean bean = new OpinionDataBean.RequestIdDataBean();
        bean.setIds(id);

        iHomeDetailModel.postOpinionDelete(new Gson().toJson(bean), new OnLoadDataListener<String>() {
            @Override
            public void onSuccess(BaseResponse<String> t) {
                mView.postOpinionCWBD(t);
            }

            @Override
            public void onFailure(String error) {
                mView.responseFailed(error);
            }
        });
    }



}
